#ifndef PLUGINHANDLER_H
#define PLUGINHANDLER_H

#include "../gui/whalebutton.h"
#include "whaleplugin.h"
#include "../gui/whalepluginstarter.h"
#include "../gui/interfaces.h"

#include <QList>
#include <QMap>
#include <QDir>

class TabScreen;
class WhaleTabBase;
class WhaleButton;

// Plugin management class
class PluginHandler : public QObject {
    Q_OBJECT

    public:
        PluginHandler( QDir pluginsDir );
        QMap< QString, WhalePluginStarter * > starters(); // get buttons that display tabs
        WhalePlugin * getPlugin( QString name ); // get tab plugin with this name
        QMap<  QString, WhalePlugin * > plugins();
        WhaleTabBase * recreateTab( QString name, QVariant constructors );

    public slots:
        void loadPlugins(); // load available plugins
        void requestTab();
        void enablePlugin( QString name ); // enable plugin and reset interface
        void disablePlugin( QString name ); // disable plugin and reset interface
        void savePluginStates(); // save which plugins are enabled
        void restorePluginStates(); // restore list of enabled plugins from last session

    signals:
        void newTabRequest( WhaleTabBase * tab ); // request displaying a new tab; handled by tabmanager
        void pluginStateChanged( bool state );

    private:
        void handleTabPlugin( TabInterface * iTab, QObject * plugin ); // handle loaded tab plugin
        WhalePlugin * getPluginObject( QString filename ); // create plugin object from file

        QMap< QString, WhalePluginStarter * > mStarters;
        QMap< QString, WhalePlugin * > mPlugins;
        QDir mPluginsDir;
};

#endif
